import type { VxeTableGridOptions } from '@vben/plugins/vxe-table';

import type { VbenFormSchema } from '#/adapter/form';
import type { WorkOrderModel } from '#/api/production/models';

import {
  useWorkOrderStatusOptions,
  useWorkOrderTypeOptions,
} from '#/api/production/models';

/**
 * 获取表格查询表单的字段配置。
 */
export function useSearchSchema(): VbenFormSchema[] {
  return [
    {
      component: 'Input',
      componentProps: {
        allowClear: true,
      },
      fieldName: 'wo',
      label: '工单编号',
    },
  ];
}

/**
 * 获取表格列配置。
 */
export function useColumns(): VxeTableGridOptions<WorkOrderModel>['columns'] {
  return [
    { type: 'seq', width: 60 },
    { field: 'wo', title: '工单编号', width: 160 },
    { field: 'product.name', title: '产品', width: 140 },
    { field: 'line.lineName', title: '产线', width: 140 },
    {
      field: 'woType',
      title: '工单类型',
      width: 100,
      cellRender: {
        name: 'CellTag',
        options: useWorkOrderTypeOptions(),
      },
    },
    {
      field: 'planQty',
      title: '计划生产数量',
      width: 120,
      cellRender: {
        attrs: {
          color: 'default',
        },
        name: 'CellTag',
      },
    },
    {
      field: 'startedQty',
      title: '已投产数量',
      width: 120,
      cellRender: {
        attrs: {
          color: '#2db7f5',
        },
        name: 'CellTag',
      },
    },
    {
      field: 'goodQty',
      title: '良品数量',
      width: 120,
      cellRender: {
        attrs: {
          color: '#87d068',
        },
        name: 'CellTag',
      },
    },
    {
      field: 'scrappedQty',
      title: '报废数量',
      width: 120,
      cellRender: {
        attrs: {
          color: '#cd201f',
        },
        name: 'CellTag',
      },
    },
    {
      field: 'status',
      title: '状态',
      width: 100,
      cellRender: {
        name: 'CellTag',
        options: useWorkOrderStatusOptions(),
      },
    },
    { field: 'remark', title: '备注', minWidth: 100 },
    {
      field: 'action',
      title: '操作',
      fixed: 'right',
      width: 120,
      slots: { default: 'action' },
    },
  ];
}
